home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / • Obsolete⁄Unsupported / ScriptX / Code Samples / autofind / source / grphmenu.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  3.3 KB  |  113 lines  |  [TEXT/ttxt]

  1. --<<<
  2. -- Filename: 
  3. --     grphmenu.sx
  4.  
  5. -- Other Files Required:
  6. --     none
  7.  
  8. -- Purpose:  
  9. --     Create a GrapherMenu class.
  10.  
  11. -- Specialized Classes:  
  12. --     GrapherMenu
  13.  
  14. -- Instructions to User: 
  15. --        GrapherMenu is a centered menu with a graphic background, meant to
  16. --        hold a list of graphable properties which can be added to dynamically.
  17.  
  18. -- Author:
  19. --      Dionn Stewart, Steve Gano, Steve Mayer, Ray Davis
  20.  
  21. in module Autofinder
  22.  
  23. class GrapherMenu (Menu)
  24. instance variables
  25.     hmarg        -- left margin for menu items
  26.     vmarg        -- top margin for menu items
  27.     itemWidth    -- width of menu items
  28.     itemHeight    -- height of menu items
  29.     fontChanges    -- keyed linked list of text attributes to change
  30. end
  31.  
  32. method init self {class GrapherMenu} #rest args #key \
  33.     hmarg:(20) vmarg:(20) \
  34.     itemWidth:(undefined) itemHeight:(25) \
  35.     fontChanges:(new KeyedLinkedList) \
  36.     background:(undefined) boundary:(undefined) ->
  37. (
  38.       apply nextMethod self placement:@menuRight args
  39.      self.hmarg := hmarg
  40.       self.vmarg := vmarg
  41.       self.itemWidth := itemWidth
  42.       self.itemHeight := itemHeight
  43.       self.fontChanges := fontChanges
  44.     self
  45. )
  46.  
  47. method afterinit self {class GrapherMenu} #rest args #key \
  48.     background: (undefined) boundary: (undefined) ->
  49. (
  50.     apply nextMethod self args
  51.      self.layoutController.wholespace:= false
  52.       if background <> undefined do
  53.       (
  54.           background.z := -1        -- That's why we call it a background
  55.           append self background
  56.           if boundary = undefined do
  57.               boundary := background.boundary
  58.     )
  59.     self.targetPresenter.boundary := boundary
  60.      if self.itemWidth = undefined do
  61.         self.itemWidth := self.targetPresenter.width - (self.hmarg * 2)
  62.      self
  63. )
  64.   
  65. -- override the place method to keep the menu in the center of the graph
  66. method place self {class GrapherMenu} theEvent ->
  67. (
  68.     nextMethod self theEvent
  69.     -- If we counted correctly, the next line should reach our Grapher
  70.     local stage := self.invoker.presentedBy.presentedBy.presentedBy
  71.     self.x:= (stage.width - self.width)/2
  72.     self.y:= (stage.height - self.height)/2
  73.     self
  74. )
  75.  
  76. method addPropertyToMenu self {class GrapherMenu} prop ->
  77. (
  78.     local pb := makePropertyButton self prop.axisTarget
  79.     -- when button is activated call changeproperty on the axis that invoked
  80.     -- the menu with this property
  81.     pb.activateAction := (adata button -> changeProperty adata.invoker.presentedBy prop)
  82.     pb.authordata := self
  83.     -- add the pushbutton to the menu
  84.     append self pb
  85.      if (append self.layoutController pb) = 1 do
  86.          -- Set the top margin
  87.          self.layoutController[1].y := self.vmarg
  88. )
  89.  
  90. -- Subclasses or instances can override this to set the attributes
  91. -- of the textpresenters of the buttons, or change the buttons
  92. -- to some other type of presenter
  93.  
  94. method makePropertyButton self {class GrapherMenu} target ->
  95. (
  96.     local pb := new pushbutton \
  97.         pressedPresenter:\
  98.             (new textPresenter boundary:(new rect x2:self.itemWidth y2:self.itemHeight) \
  99.             fill:undefined stroke:blackbrush target:target) \
  100.         releasedPresenter:\
  101.             (new textPresenter boundary:(new rect x2:self.itemWidth y2:self.itemHeight) \
  102.             fill:undefined stroke:undefined target:target)
  103.     setDefaultAttr pb.releasedPresenter @brush whitebrush
  104.     forEachBinding self.fontChanges (key val arg ->
  105.         setDefaultAttr pb.pressedPresenter key val
  106.         setDefaultAttr pb.releasedPresenter key val
  107.     ) undefined
  108.     pb.x := self.hmarg
  109.     pb
  110. )
  111. "Compiled grphmenu.sx"
  112. -->>>
  113.